package org.excel4j.creators;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import jxl.Sheet;

import org.apache.commons.collections.map.LRUMap;
import org.excel4j.ExcelColumn;

import com.google.common.base.Function;

public class ColumnCreator implements Function<Integer, ExcelColumn>{

	private final Sheet sheet;
	@SuppressWarnings("unchecked")
	private ConcurrentMap<Integer,ExcelColumn> map = new ConcurrentHashMap<Integer, ExcelColumn>(new LRUMap(100));
	
	
	public ColumnCreator(Sheet sheet) {
		this.sheet = sheet;
	}
	
	
	public ExcelColumn apply(Integer arg0) {
		ExcelColumn column = map.get(arg0);
		if (column == null)
		{
			map.putIfAbsent(arg0,new ExcelColumn(sheet, arg0+1));
		}
		return map.get(arg0);
	}

}
